package com.laikan.reader.database;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;

import java.io.Serializable;

/**
 * 书籍表
 * (S) server需要返回的字段
 * (L) server不需要返回的字段,仅本地操作处理或当前不需要服务器返回
 */
@Entity
public class Book implements Serializable {

    @Id
    private String id;  //bookId 书籍Id(S)
    @Property (
        nameInDb = "BOOK_NAME"
    )
    private String name;    //书名(S)
    private String authorName;  //作者名(S)
    private String icon;    //book cover 书封面(S)
    private String introduce;   //书籍简介(S)
    private String status;  //书目类型 限免 一折 完本(绶带) ...(S)
    private String updateTime;  //更新时间 用于判断书籍章节是否有更新（显示更新绶带)(S)
    private String newChapterCount;     //更新新章节总数(S)
    private String chapterTotalCount;   //章节总数 分完卷，把卷去掉之后的章节总数(S)
    private String bookGroup;   //1男频, 2女频, 3出版, .... 与付费购买计算相关(S)

    private boolean isUpdated;  //是否已经更新完毕(目录已经下载且阅读过)(L)
    private String currentRecorder;    //当前阅读指针(L) name_id_index  --> 当前阅读章节名_当前阅读章节ID_当前阅读指针
    private String customGroup;     //书架页分组 记录创建的目录名字(L)
    private double sortIndex;    //排序id (记录书架页拖动排序的位置)(L)

    @Generated(hash = 732472098)
    public Book(String id, String name, String authorName, String icon, String introduce,
            String status, String updateTime, String newChapterCount,
            String chapterTotalCount, String bookGroup, boolean isUpdated,
            String currentRecorder, String customGroup, double sortIndex) {
        this.id = id;
        this.name = name;
        this.authorName = authorName;
        this.icon = icon;
        this.introduce = introduce;
        this.status = status;
        this.updateTime = updateTime;
        this.newChapterCount = newChapterCount;
        this.chapterTotalCount = chapterTotalCount;
        this.bookGroup = bookGroup;
        this.isUpdated = isUpdated;
        this.currentRecorder = currentRecorder;
        this.customGroup = customGroup;
        this.sortIndex = sortIndex;
    }

    @Generated(hash = 1839243756)
    public Book() {
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthorName() {
        return authorName;
    }

    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getIntroduce() {
        return introduce;
    }

    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getNewChapterCount() {
        return newChapterCount;
    }

    public void setNewChapterCount(String newChapterCount) {
        this.newChapterCount = newChapterCount;
    }

    public String getChapterTotalCount() {
        return chapterTotalCount;
    }

    public void setChapterTotalCount(String chapterTotalCount) {
        this.chapterTotalCount = chapterTotalCount;
    }

    public String getBookGroup() {
        return bookGroup;
    }

    public void setBookGroup(String bookGroup) {
        this.bookGroup = bookGroup;
    }

    public String getCurrentRecorder() {
        return currentRecorder;
    }

    public void setCurrentRecorder(String currentRecorder) {
        this.currentRecorder = currentRecorder;
    }

    public String getCustomGroup() {
        return customGroup;
    }

    public void setCustomGroup(String customGroup) {
        this.customGroup = customGroup;
    }

    public double getSortIndex() {
        return sortIndex;
    }

    public void setSortIndex(double sortIndex) {
        this.sortIndex = sortIndex;
    }

    public boolean getIsUpdated() {
        return this.isUpdated;
    }

    public void setIsUpdated(boolean isUpdated) {
        this.isUpdated = isUpdated;
    }

    /**
     * 该数组返回三个值
     * 0,当前阅读章节名
     * 1,当前阅读章节id
     * 2,当前阅读指针
     * @return
     */
    public String[] recorderSplit(){
        return currentRecorder.split("_");
    }

    public History convertHistory(){
        History history = new History();
        history.setBookId(getId());
        history.setBookName(getName());
        history.setBookCover(getIcon());
        history.setAuthorName(getAuthorName());
        return history;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Book){
            Book book = (Book)obj;
            if (this.getId().equals(book.getId())){
                return true;
            }
        }
        return false;
    }
}
